package com.heima.safe.aliyun.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

/**
 * @author mgw
 * @create 2021/10/6 19:54
 */
@Component
@Aspect
public class AcknowledgmentAspcet {
    /**
     * 环绕通知
     */
    @Around("execution(* com.heima.safe.aliyun.mq.*.*(..))")
    public Object ackcommit(ProceedingJoinPoint joinPoint) {
        Class declaringType = joinPoint.getSignature().getDeclaringType();
        Object[] args = joinPoint.getArgs();
        Object result=null;
        try {
            result = joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return result ;
        }
        //偏移量提交
        Acknowledgment acknowledgment=(Acknowledgment) args[1];
        acknowledgment.acknowledge();
        return result;
    }
}
